home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / cc-mode.info-1.z / cc-mode.info-1
Encoding:
GNU Info File  |  1998-05-21  |  47.2 KB  |  1,221 lines

  1. This is Info file ../info/cc-mode.info, produced by Makeinfo version
  2. 1.68 from the input file cc-mode.texi.
  3.  
  4.    Copyright (C) 1995, 1996 Free Software Foundation, Inc.
  5.  
  6. 
  7. File: cc-mode.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  8.  
  9. * Menu:
  10.  
  11. * Introduction::
  12. * Getting Connected::
  13. * New Indentation Engine::
  14. * Minor Modes::
  15. * Commands::
  16. * Customizing Indentation::
  17. * Syntactic Symbols::
  18. * Performance Issues::
  19. * Frequently Asked Questions::
  20. * Getting the latest CC Mode release::
  21. * Sample .emacs File::
  22. * Limitations and Known Bugs::
  23. * Mailing Lists and Submitting Bug Reports::
  24. * Concept Index::
  25. * Command Index::               Command Index
  26. * Key Index::                   Key Index
  27. * Variable Index::              Variable Index
  28.  
  29. 
  30. File: cc-mode.info,  Node: Introduction,  Next: Getting Connected,  Prev: Top,  Up: Top
  31.  
  32. Introduction
  33. ************
  34.  
  35.    Welcome to CC Mode.  This is a GNU Emacs mode for editing files
  36. containing C, C++, Objective-C, Java, and IDL code.  This incarnation of
  37. the mode is descendant from `c-mode.el' (also called "Boring Old C
  38. Mode" or BOCM `:-)', and `c++-mode.el' version 2, which I have been
  39. maintaining since 1992.  CC Mode represents a significant milestone in
  40. the mode's life.  It has been fully merged back with Emacs 19's
  41. `c-mode.el'. Also a new, more intuitive and flexible mechanism for
  42. controlling indentation has been developed.
  43.  
  44.    CC Mode supports the editing of K&R and ANSI C, "ARM" (1) C++,
  45. Objective-C, Java and IDL(2) files.  In this way, you can easily set up
  46. consistent coding styles for use in editing all C, C++, Objective-C,
  47. Java and IDL programs. CC Mode does *not* handle font-locking (a.k.a.
  48. syntax coloring, keyword highlighting) or anything of that nature, for
  49. any of these modes.  Font-locking is handled by other Emacs packages.
  50.  
  51.    This manual will describe the following:
  52.  
  53.    * How to get started using CC Mode.
  54.  
  55.    * How the new indentation engine works.
  56.  
  57.    * How to customize the new indentation engine.
  58.  
  59.    Note that the name of this package is "CC Mode", but there is no top
  60. level `cc-mode' entry point.  All of the variables, commands, and
  61. functions in CC Mode are prefixed with `c-<THING>', and `c-mode',
  62. `c++-mode', `objc-mode', `java-mode', and `idl-mode' entry points are
  63. provided.  This file is intended to be a replacement for `c-mode.el'
  64. and `c++-mode.el'.
  65.  
  66.    This distribution also contains a file called `cc-compat.el' which
  67. should ease your transition from BOCM to CC Mode.  If you have a BOCM
  68. configuration you are really happy with, and want to postpone learning
  69. how to configure CC Mode, take a look at that file.  It maps BOCM
  70. configuration variables to CC Mode's new indentation model.  It is not
  71. actively supported so for the long run, you should learn how to
  72. customize CC Mode to support your coding style.
  73.  
  74.    A special word of thanks goes to Krishna Padmasola for his work in
  75. converting the original `README' file to Texinfo format.  I'd also like
  76. to thank all the CC Mode victims who help enormously during the early
  77. beta stages of CC Mode's development.
  78.  
  79.    ---------- Footnotes ----------
  80.  
  81.    (1) "The Annotated C++ Reference Manual", by Ellis and Stroustrup.
  82.  
  83.    (2) CORBA's Interface Definition Language
  84.  
  85. 
  86. File: cc-mode.info,  Node: Getting Connected,  Next: New Indentation Engine,  Prev: Introduction,  Up: Top
  87.  
  88. Getting Connected
  89. *****************
  90.  
  91.    If you got this version of CC Mode with Emacs or XEmacs, it should
  92. work just fine right out of the box.  Note however that you may not have
  93. the latest CC Mode release and may want to upgrade your copy.
  94.  
  95.    If you are upgrading an existing CC Mode installation, please see the
  96. `README' file for installation details.  CC Mode may not work with
  97. older versions of Emacs or XEmacs.  See the CC Mode release notes Web
  98. pages for the latest information on Emacs version and package
  99. compatibility, etc.  The Web page locations are outlined in *Note
  100. Getting the latest CC Mode release::.
  101.  
  102.    *Note that CC Mode no longer works with Emacs 18!*  The
  103. `cc-mode-18.el' file is no longer distributed with CC Mode.  If you
  104. haven't upgraded from Emacs 18 by now, you are out of luck.
  105.  
  106.    You can find out what version of CC Mode you are using by visiting a
  107. C file and entering `M-x c-version RET'.  You should see this message in
  108. the echo area:
  109.  
  110.      Using CC Mode version 5.XX
  111.  
  112. where `XX' is the minor release number.
  113.  
  114. 
  115. File: cc-mode.info,  Node: New Indentation Engine,  Next: Minor Modes,  Prev: Getting Connected,  Up: Top
  116.  
  117. New Indentation Engine
  118. **********************
  119.  
  120.    CC Mode has a new indentation engine, providing a simplified, yet
  121. flexible and general mechanism for customizing indentation. It separates
  122. indentation calculation into two steps: first, CC Mode analyzes the
  123. line of code being indented to determine the kind of language construct
  124. it's looking at, then it applies user defined offsets to the current
  125. line based on this analysis.
  126.  
  127.    This section will briefly cover how indentation is calculated in CC
  128. Mode. It is important to understand the indentation model being used so
  129. that you will know how to customize CC Mode for your personal coding
  130. style.
  131.  
  132. * Menu:
  133.  
  134. * Syntactic Analysis::
  135. * Indentation Calculation::
  136.  
  137. 
  138. File: cc-mode.info,  Node: Syntactic Analysis,  Next: Indentation Calculation,  Up: New Indentation Engine
  139.  
  140. Syntactic Analysis
  141. ==================
  142.  
  143.    The first thing CC Mode does when indenting a line of code, is to
  144. analyze the line, determining the "syntactic component list" of the
  145. construct on that line.  A syntactic component consists of a pair of
  146. information (in lisp parlance, a *cons cell*), where the first part is
  147. a "syntactic symbol", and the second part is a "relative buffer
  148. position".  Syntactic symbols describe elements of C code (1), e.g.
  149. `statement', `substatement', `class-open', `class-close', etc.  *Note
  150. Syntactic Symbols::, for a complete list of currently recognized
  151. syntactic symbols and their semantics.  The variable `c-offsets-alist'
  152. also contains the list of currently supported syntactic symbols.
  153.  
  154.    Conceptually, a line of C code is always indented relative to the
  155. indentation of some line higher up in the buffer.  This is represented
  156. by the relative buffer position in the syntactic component.
  157.  
  158.    Here is an example.  Suppose we had the following code as the only
  159. thing in a `c++-mode' buffer (2):
  160.  
  161.        1: void swap( int& a, int& b )
  162.        2: {
  163.        3:     int tmp = a;
  164.        4:     a = b;
  165.        5:     b = tmp;
  166.        6: }
  167.  
  168.    We can use the command `C-c C-s' (`c-show-syntactic-information') to
  169. simply report what the syntactic analysis is for the current line.
  170. Running this command on line 4 of this example, we'd see in the echo
  171. area(3):
  172.  
  173.      ((statement . 35))
  174.  
  175.    This tells us that the line is a statement and it is indented
  176. relative to buffer position 35, which happens to be the `i' in `int' on
  177. line 3.  If you were to move point to line 3 and hit `C-c C-s', you
  178. would see:
  179.  
  180.      ((defun-block-intro . 29))
  181.  
  182.    This indicates that the `int' line is the first statement in a top
  183. level function block, and is indented relative to buffer position 29,
  184. which is the brace just after the function header.
  185.  
  186.    Here's another example:
  187.  
  188.        1: int add( int val, int incr, int doit )
  189.        2: {
  190.        3:     if( doit )
  191.        4:         {
  192.        5:             return( val + incr );
  193.        6:         }
  194.        7:     return( val );
  195.        8: }
  196.  
  197. Hitting `C-c C-s' on line 4 gives us:
  198.  
  199.      ((substatement-open . 46))
  200.  
  201. which tells us that this is a brace that *opens* a substatement block.
  202. (4)
  203.  
  204.    Syntactic component lists can contain more than one component, and
  205. individual syntactic components need not have relative buffer positions.
  206. The most common example of this is a line that contains a "comment only
  207. line".
  208.  
  209.        1: void draw_list( List<Drawables>& drawables )
  210.        2: {
  211.        3:         // call the virtual draw() method on each element in list
  212.        4:     for( int i=0; i < drawables.count(), ++i )
  213.        5:     {
  214.        6:         drawables[i].draw();
  215.        7:     }
  216.        8: }
  217.  
  218. Hitting `C-c C-s' on line 3 of this example gives:
  219.  
  220.      ((comment-intro) (defun-block-intro . 46))
  221.  
  222. and you can see that the syntactic component list contains two syntactic
  223. components.  Also notice that the first component, `(comment-intro)'
  224. has no relative buffer position.
  225.  
  226.    ---------- Footnotes ----------
  227.  
  228.    (1) or C++, Objective-C, Java or IDL code.  In general, for the rest
  229. of this manual I'll use the term "C code" to refer to all the C-like
  230. dialects, unless otherwise noted.
  231.  
  232.    (2) The line numbers in this and future examples don't actually
  233. appear in the buffer, of course!
  234.  
  235.    (3) With a universal argument (i.e. `C-u C-c C-s') the analysis is
  236. inserted into the buffer as a comment on the current line.
  237.  
  238.    (4) A "substatement" indicates the line after a conditional
  239. statement, such as `if', `else', `while', `do', `switch', or `for' in
  240. C.  A "substatement block" is a brace block following one of those
  241. conditionals.
  242.  
  243. 
  244. File: cc-mode.info,  Node: Indentation Calculation,  Prev: Syntactic Analysis,  Up: New Indentation Engine
  245.  
  246. Indentation Calculation
  247. =======================
  248.  
  249.    Indentation for the current line is calculated using the syntactic
  250. component list derived in step 1 above (see *Note Syntactic Analysis::).
  251. Each component contributes to the final total indentation of the line in
  252. two ways.
  253.  
  254.    First, the syntactic symbols are looked up in the `c-offsets-alist'
  255. variable, which is an association list of syntactic symbols and the
  256. offsets to apply for those symbols.  These offsets are added to a
  257. running total.
  258.  
  259.    Second, if the component has a relative buffer position, CC Mode
  260. adds the column number of that position to the running total.  By adding
  261. up the offsets and columns for every syntactic component on the list,
  262. the final total indentation for the current line is computed.
  263.  
  264.    Let's use our two code examples above to see how this works.  Here is
  265. our first example again:
  266.  
  267.          1: void swap( int& a, int& b )
  268.          2: {
  269.          3:     int tmp = a;
  270.          4:     a = b;
  271.          5:     b = tmp;
  272.          6: }
  273.  
  274.    Let's say point is on line 3 and we hit the <TAB> key to re-indent
  275. the line.  Remember that the syntactic component list for that line is:
  276.  
  277.      ((defun-block-intro . 29))
  278.  
  279. CC Mode looks up `defun-block-intro' in the `c-offsets-alist' variable.
  280. Let's say it finds the value `4'; it adds this to the running total
  281. (initialized to zero), yielding a running total indentation of 4 spaces.
  282.  
  283.    Next CC Mode goes to buffer position 29 and asks for the current
  284. column.  This brace is in column zero, so CC Mode adds `0' to the
  285. running total.  Since there is only one syntactic component on the list
  286. for this line, indentation calculation is complete, and the total
  287. indentation for the line is 4 spaces.
  288.  
  289.    Here's another example:
  290.  
  291.          1: int add( int val, int incr, int doit )
  292.          2: {
  293.          3:     if( doit )
  294.          4:         {
  295.          5:             return( val + incr );
  296.          6:         }
  297.          7:     return( val );
  298.          8: }
  299.  
  300.    If we were to hit `TAB' on line 4 in the above example, the same
  301. basic process is performed, despite the differences in the syntactic
  302. component list.  Remember that the list for this line is:
  303.  
  304.      ((substatement-open . 46))
  305.  
  306.    Here, CC Mode first looks up the `substatement-open' symbol in
  307. `c-offsets-alist'. Let's say it finds the value `4'.  This yields a
  308. running total of 4.  CC Mode then goes to buffer position 46, which is
  309. the `i' in `if' on line 3.  This character is in the fourth column on
  310. that line so adding this to the running total yields an indentation for
  311. the line of 8 spaces.
  312.  
  313.    Simple, huh?
  314.  
  315.    Actually, the mode usually just does The Right Thing without you
  316. having to think about it in this much detail.  But when customizing
  317. indentation, it's helpful to understand the general indentation model
  318. being used.
  319.  
  320.    As you configure CC Mode, you might want to set the variable
  321. `c-echo-syntactic-information-p' to non-`nil' so that the syntactic
  322. component list and calculated offset will always be echoed in the
  323. minibuffer when you hit `TAB'.
  324.  
  325. 
  326. File: cc-mode.info,  Node: Minor Modes,  Next: Commands,  Prev: New Indentation Engine,  Up: Top
  327.  
  328. Minor Modes
  329. ***********
  330.  
  331.    CC Mode contains two minor-mode-like features that you should find
  332. useful while you enter new C code.  The first is called "auto-newline"
  333. mode, and the second is called "hungry-delete" mode.  These minor modes
  334. can be toggled on and off independently, and CC Mode can be configured
  335. so that it starts up with any combination of these minor modes.  By
  336. default, both of these minor modes are turned off.
  337.  
  338.    The state of the minor modes is always reflected in the minor mode
  339. list on the modeline of the CC Mode buffer.  When auto-newline mode is
  340. enabled, you will see `C/a' on the mode line (1).  When hungry delete
  341. mode is enabled you would see `C/h' and when both modes are enabled,
  342. you'd see `C/ah'.
  343.  
  344.    CC Mode provides keybindings which allow you to toggle the minor
  345. modes on the fly while editing code.  To toggle just the auto-newline
  346. state, hit `C-c C-a' (`c-toggle-auto-state').  When you do this, you
  347. should see the `a' indicator either appear or disappear on the
  348. modeline.  Similarly, to toggle just the hungry-delete state, use `C-c
  349. C-d' (`c-toggle-hungry-state'), and to toggle both states, use `C-c
  350. C-t' (`c-toggle-auto-hungry-state').
  351.  
  352.    To set up the auto-newline and hungry-delete states to your preferred
  353. values, you would need to add some lisp to your `.emacs' file that
  354. called one of the `c-toggle-*-state' functions directly.  When called
  355. programmatically, each function takes a numeric value, where a positive
  356. number enables the minor mode, a negative number disables the mode, and
  357. zero toggles the current state of the mode.
  358.  
  359.    So for example, if you wanted to enable both auto-newline and
  360. hungry-delete for all your C file editing, you could add the following
  361. to your `.emacs' file:
  362.  
  363.      (add-hook 'c-mode-common-hook
  364.            '(lambda () (c-toggle-auto-hungry-state 1)))
  365.  
  366. * Menu:
  367.  
  368. * Auto-newline insertion::
  369. * Hungry-deletion of whitespace::
  370. * Auto-fill mode interaction::
  371.  
  372.    ---------- Footnotes ----------
  373.  
  374.    (1) Remember that the `C' could be replaced with `C++', `ObjC',
  375. `Java' or `IDL'.
  376.  
  377. 
  378. File: cc-mode.info,  Node: Auto-newline insertion,  Next: Hungry-deletion of whitespace,  Up: Minor Modes
  379.  
  380. Auto-newline insertion
  381. ======================
  382.  
  383.    Auto-newline minor mode works by enabling certain "electric
  384. commands".  Electric commands are typically bound to special characters
  385. such as the left and right braces, colons, semi-colons, etc., which when
  386. typed, perform some magic formatting in addition to inserting the typed
  387. character.  As a general rule, electric commands are only electric when
  388. the following conditions apply:
  389.  
  390.    * Auto-newline minor mode is enabled, as evidenced by a `C/a' or
  391.      `C/ah' indicator on the modeline.
  392.  
  393.    * The character was not typed inside of a literal (1).
  394.  
  395.    * No numeric argument was supplied to the command (i.e. it was typed
  396.      as normal, with no `C-u' prefix).
  397.  
  398. * Menu:
  399.  
  400. * Hanging Braces::
  401. * Hanging Colons::
  402. * Hanging Semi-colons and commas::
  403. * Other electric commands::
  404. * Clean-ups::
  405.  
  406.    ---------- Footnotes ----------
  407.  
  408.    (1) A "literal" is defined as any comment, string, or cpp macro
  409. definition.  These constructs are also known as "syntactic whitespace"
  410. since they are usually ignored when scanning C code.
  411.  
  412. 
  413. File: cc-mode.info,  Node: Hanging Braces,  Next: Hanging Colons,  Up: Auto-newline insertion
  414.  
  415. Hanging Braces
  416. --------------
  417.  
  418.    When you type either an open or close brace (i.e. `{' or `}'), the
  419. electric command `c-electric-brace' gets run.  This command has two
  420. electric formatting behaviors.  First, it will perform some
  421. re-indentation of the line the brace was typed on, and second, it will
  422. add various newlines before and/or after the typed brace.
  423. Re-indentation occurs automatically whenever the electric behavior is
  424. enabled.  If the brace ends up on a line other than the one it was typed
  425. on, then that line is also indented according to `c-offsets-alist'.
  426.  
  427.    The insertion of newlines is controlled by the
  428. `c-hanging-braces-alist' variable.  This variable contains a mapping
  429. between syntactic symbols related to braces, and a list of places to
  430. insert a newline.  The syntactic symbols that are useful for this list
  431. are: `class-open', `class-close', `defun-open', `defun-close',
  432. `inline-open', `inline-close', `brace-list-open', `brace-list-close',
  433. `brace-list-intro', `brace-list-entry', `block-open', `block-close',
  434. `substatement-open', `statement-case-open', `extern-lang-open', and
  435. `extern-lang-close'.  *Note Syntactic Symbols:: for a more detailed
  436. description of these syntactic symbols.
  437.  
  438.    The value associated with each syntactic symbol in this association
  439. list is called an ACTION which can be either a function or a list.
  440. *Note Custom Brace and Colon Hanging:: for a more detailed discussion of
  441. using a function as a brace hanging ACTION.
  442.  
  443.    When the ACTION is a list, it can contain any combination of the
  444. symbols `before' and `after', directing CC Mode where to put newlines
  445. in relationship to the brace being inserted.  Thus, if the list
  446. contains only the symbol `after', then the brace is said to "hang" on
  447. the right side of the line, as in:
  448.  
  449.      // here, open braces always `hang'
  450.      void spam( int i ) {
  451.          if( i == 7 ) {
  452.              dosomething(i);
  453.          }
  454.      }
  455.  
  456.    When the list contains both `after' and `before', the braces will
  457. appear on a line by themselves, as shown by the close braces in the
  458. above example.  The list can also be empty, in which case no newlines
  459. are added either before or after the brace.
  460.  
  461.    For example, the default value of `c-hanging-braces-alist' is:
  462.  
  463.      (defvar c-hanging-braces-alist '((brace-list-open)
  464.                                       (substatement-open after)
  465.                                       (block-close . c-snug-do-while)
  466.                                       (extern-lang-open after)))
  467.  
  468. which says that `brace-list-open' braces should both hang on the right
  469. side, and allow subsequent text to follow on the same line as the
  470. brace.  Also, `substatement-open' and `extern-lang-open' braces should
  471. hang on the right side, but subsequent text should follow on the next
  472. line.  Here, in the `block-close' entry, you also see an example of
  473. using a function as an ACTION.
  474.  
  475.    A word of caution: it is not a good idea to hang top-level construct
  476. introducing braces, such as `class-open' or `defun-open'.  Emacs makes
  477. an assumption that such braces will always appear in column zero,
  478. hanging such braces can introduce performance problems.  *Note
  479. Performance Issues:: for more information.
  480.  
  481. 
  482. File: cc-mode.info,  Node: Hanging Colons,  Next: Hanging Semi-colons and commas,  Prev: Hanging Braces,  Up: Auto-newline insertion
  483.  
  484. Hanging Colons
  485. --------------
  486.  
  487.    Using a mechanism similar to brace hanging (see *Note Hanging
  488. Braces::), colons can also be made to hang using the variable
  489. `c-hanging-colons-alist'.  The syntactic symbols appropriate for this
  490. assocation list are: `case-label', `label', `access-label',
  491. `member-init-intro', and `inher-intro'.  Note however that for
  492. `c-hanging-colons-alist', ACTIONs as functions are not supported. See
  493. also *Note Custom Brace and Colon Hanging:: for details.
  494.  
  495.    In C++, double-colons are used as a scope operator but because these
  496. colons always appear right next to each other, newlines before and after
  497. them are controlled by a different mechanism, called "clean-ups" in CC
  498. Mode.  *Note Clean-ups:: for details.
  499.  
  500. 
  501. File: cc-mode.info,  Node: Hanging Semi-colons and commas,  Next: Other electric commands,  Prev: Hanging Colons,  Up: Auto-newline insertion
  502.  
  503. Hanging Semi-colons and commas
  504. ------------------------------
  505.  
  506.    Semicolons and commas are also electric in CC Mode, but since these
  507. characters do not correspond directly to syntactic symbols, a different
  508. mechanism is used to determine whether newlines should be automatically
  509. inserted after these characters.  *Note Customizing Semi-colons and
  510. Commas:: for details.
  511.  
  512. 
  513. File: cc-mode.info,  Node: Other electric commands,  Next: Clean-ups,  Prev: Hanging Semi-colons and commas,  Up: Auto-newline insertion
  514.  
  515. Other electric commands
  516. -----------------------
  517.  
  518.    A few other keys also provide electric behavior.  For example `#'
  519. (`c-electric-pound') is electric when typed as the first non-whitespace
  520. character on a line.  In this case, the variable
  521. `c-electric-pound-behavior' is consulted for the electric behavior.
  522. This variable takes a list value, although the only element currently
  523. defined is `alignleft', which tells this command to force the `#'
  524. character into column zero.  This is useful for entering cpp macro
  525. definitions.
  526.  
  527.    Stars and slashes (i.e. `*' and `/', `c-electric-star' and
  528. `c-electric-slash' respectively) are also electric under certain
  529. circumstances.  If a star is inserted as the second character of a C
  530. style block comment on a "comment-only" line, then the comment
  531. delimiter is indented as defined by `c-offsets-alist'.  A comment-only
  532. line is defined as a line which contains only a comment, as in:
  533.  
  534.      void spam( int i )
  535.      {
  536.              // this is a comment-only line...
  537.          if( i == 7 )                             // but this is not
  538.          {
  539.              dosomething(i);
  540.          }
  541.      }
  542.  
  543.    Likewise, if a slash is inserted as the second slash in a C++ style
  544. line comment (also only on a comment-only line), then the line is
  545. indented as defined by `c-offsets-alist'.
  546.  
  547.    Less-than and greater-than signs (`c-electric-lt-gt') are also
  548. electric, but only in C++ mode.  Hitting the second of two `<' or `>'
  549. keys re-indents the line if it is a C++ style stream operator.
  550.  
  551. 
  552. File: cc-mode.info,  Node: Clean-ups,  Prev: Other electric commands,  Up: Auto-newline insertion
  553.  
  554. Clean-ups
  555. ---------
  556.  
  557.    "Clean-ups" are a mechanism complementary to colon and brace
  558. hanging.  On the surface, it would seem that clean-ups overlap the
  559. functionality provided by the `c-hanging-*-alist' variables, and
  560. similarly, clean-ups are only enabled when auto-newline minor mode is
  561. enabled.  Clean-ups are used however to adjust code "after-the-fact",
  562. i.e. to eliminate some whitespace that is inserted by electric
  563. commands, or whitespace that contains intervening constructs.
  564.  
  565.    You can configure CC Mode's clean-ups by setting the variable
  566. `c-cleanup-list', which is a list of clean-up symbols.  By default, CC
  567. Mode cleans up only the `scope-operator' construct, which is necessary
  568. for proper C++ support.  Note that clean-ups are only performed when
  569. the construct does not occur within a literal (see *Note Auto-newline
  570. insertion::), and when there is nothing but whitespace appearing
  571. between the individual components of the construct.
  572.  
  573.    There are currently only five specific constructs that CC Mode can
  574. clean up, as indicated by these symbols:
  575.  
  576.    * `brace-else-brace' -- cleans up `} else {' constructs by placing
  577.      the entire construct on a single line.  Clean-up occurs when the
  578.      open brace after the `else' is typed.  So for example, this:
  579.  
  580.           void spam(int i)
  581.           {
  582.               if( i==7 )
  583.               {
  584.                   dosomething();
  585.               }
  586.               else
  587.               {
  588.  
  589.      appears like this after the open brace is typed:
  590.  
  591.           void spam(int i)
  592.           {
  593.               if( i==7 ) {
  594.                   dosomething();
  595.               } else {
  596.  
  597.    * `brace-elseif-brace' -- similar to the `brace-else-brace'
  598.      clean-up, but cleans up `} else if (...){' constructs.  For
  599.      example:
  600.  
  601.           void spam(int i)
  602.           {
  603.               if( i==7 )
  604.               {
  605.                   dosomething();
  606.               }
  607.               else if( i==3 ) {
  608.  
  609.      appears like this after the open brace is typed:
  610.  
  611.           void spam(int i)
  612.           {
  613.               if( i==7 ) {
  614.                   dosomething();
  615.               } else if( i==3 ) {
  616.  
  617.    * `empty-defun-braces' -- cleans up braces following a top-level
  618.      function or class definition that contains no body.  Clean up
  619.      occurs when the closing brace is typed.  Thus the following:
  620.  
  621.           class Spam
  622.           {
  623.           }
  624.  
  625.      is transformed into this when the close brace is typed:
  626.  
  627.           class Spam
  628.           {}
  629.  
  630.    * `defun-close-semi' -- cleans up the terminating semi-colon on
  631.      top-level function or class definitions when they follow a close
  632.      brace. Clean up occurs when the semi-colon is typed.  So for
  633.      example, the following:
  634.  
  635.           class Spam
  636.           {
  637.           }
  638.           ;
  639.  
  640.      is transformed into this when the semi-colon is typed:
  641.  
  642.  
  643.           class Spam
  644.           {
  645.           };
  646.  
  647.    * `list-close-comma' -- cleans up commas following braces in array
  648.      and aggregate initializers.  Clean up occurs when the comma is
  649.      typed.
  650.  
  651.    * `scope-operator' -- cleans up double colons which may designate a
  652.      C++ scope operator split across multiple lines(1).  Clean up
  653.      occurs when the second colon is typed.  You will always want
  654.      `scope-operator' in the `c-cleanup-list' when you are editing C++
  655.      code.
  656.  
  657.    ---------- Footnotes ----------
  658.  
  659.    (1) Certain C++ constructs introduce ambiguous situations, so
  660. `scope-operator' clean-ups may not always be correct.  This usually
  661. only occurs when scoped identifiers appear in switch label tags.
  662.  
  663. 
  664. File: cc-mode.info,  Node: Hungry-deletion of whitespace,  Next: Auto-fill mode interaction,  Prev: Auto-newline insertion,  Up: Minor Modes
  665.  
  666. Hungry-deletion of whitespace
  667. =============================
  668.  
  669.    Hungry deletion of whitespace, or as it more commonly called,
  670. "hungry-delete mode", is a simple feature that some people find
  671. extremely useful.  In fact, you might find yourself wanting
  672. hungry-delete in *all* your editing modes!
  673.  
  674.    In a nutshell, when hungry-delete mode is enabled, hitting the
  675. `Backspace' key(1) will consume all preceding whitespace, including
  676. newlines and tabs.  This can really cut down on the number of
  677. `Backspace''s you have to type if, for example you made a mistake on
  678. the preceding line.
  679.  
  680.    By default, when you hit the `Backspace' key CC Mode runs the
  681. command `c-electric-backspace', which deletes text in the backwards
  682. direction.  When deleting a single character, or when `Backspace' is
  683. hit in a literal (see *Note Auto-newline insertion::), or when
  684. hungry-delete mode is disabled, the function contained in the
  685. `c-backspace-function' variable is called with one argument (the number
  686. of characters to delete).  This variable is set to
  687. `backward-delete-char-untabify' by default.
  688.  
  689.    Similarly, hitting the `DEL' key runs the command
  690. `c-electric-delete'.  Some versions of Emacs(2) support separation of
  691. the `Backspace' and `DEL' keys, so that `DEL' will delete in the
  692. forward direction when `delete-key-deletes-forward' is non-`nil'.  If
  693. your Emacs supports this, and `delete-key-deletes-forward' is
  694. non-`nil', and hungry-delete mode is enabled, then `DEL' will consume
  695. all whitespace following point.  When deleting a single character, or
  696. when `DEL' is hit in a literal, or when hungry-delete mode is disabled,
  697. the function contained in the `c-delete-function' variable is called
  698. with one argument (the number of characters to delete).  This variable
  699. is set to `delete-char' by default.
  700.  
  701.    However, if `delete-key-deletes-forward' is `nil', or your Emacs
  702. does not support separation of `Backspace' and `DEL', then
  703. `c-electric-delete' simply calls `c-electric-backspace'.
  704.  
  705.    ---------- Footnotes ----------
  706.  
  707.    (1) I say "hit the `Backspace' key" but what I really mean is "when
  708. Emacs receives the `BackSpace' keysym event".  The difference usually
  709. isn't significant to most users, but advanced users will realize that
  710. under window systems such as X, any physical key (keycap) on the
  711. keyboard can be configured to generate any keysym.  Also, the use of
  712. Emacs on TTYs will affect which keycap generates which keysym.  From a
  713. pedantic point of view, here we are only concerned with the keysym
  714. event that Emacs receives.
  715.  
  716.    (2) As of this writing, 20-Jun-1997, only XEmacs 20.3 supports this.
  717.  
  718. 
  719. File: cc-mode.info,  Node: Auto-fill mode interaction,  Prev: Hungry-deletion of whitespace,  Up: Minor Modes
  720.  
  721. Auto-fill mode interaction
  722. ==========================
  723.  
  724.    One other note about minor modes is worth mentioning here.  CC Mode
  725. now works much better with auto-fill mode (a standard Emacs minor mode)
  726. by correctly auto-filling both line (e.g. C++ style) and block (e.g. C
  727. style) oriented comments.  When `auto-fill-mode' is enabled, line
  728. oriented comments will also be auto-filled by inserting a newline at the
  729. line break, and inserting `//' at the start of the next line.
  730.  
  731.    When auto-filling block oriented comments, the behavior is dependent
  732. on the value of the variable `c-comment-continuation-stars'.  When this
  733. variable is `nil', the old behavior for auto-filling C comments is in
  734. effect.  In this case, the line is broken by closing the comment and
  735. starting a new comment on the next line.
  736.  
  737.    If you set `c-comment-continuation-stars' to a string, then a long C
  738. block comment line is broken by inserting a newline at the line break
  739. position, and inserting this string at the beginning of the next comment
  740. line.  The default value for `c-comment-continuation-stars' is `* ' (a
  741. star followed by a single space)(1).
  742.  
  743.    ---------- Footnotes ----------
  744.  
  745.    (1) To get block comment continuation lines indented under the block
  746. comment starter (e.g. the `/*'), it is not enough to set
  747. `c-comment-continuation-stars' to the empty string.  You need to do
  748. this, but you also need to set the offset for the `c' syntactic symbol
  749. to be zero.
  750.  
  751. 
  752. File: cc-mode.info,  Node: Commands,  Next: Customizing Indentation,  Prev: Minor Modes,  Up: Top
  753.  
  754. Commands
  755. ********
  756.  
  757. * Menu:
  758.  
  759. * Indentation Commands::
  760. * Other Commands::
  761.  
  762. 
  763. File: cc-mode.info,  Node: Indentation Commands,  Next: Other Commands,  Up: Commands
  764.  
  765. Indentation Commands
  766. ====================
  767.  
  768.    Various commands are provided which allow you to conveniently
  769. re-indent C constructs.  There are several things to note about these
  770. indentation commands.  First, when you change your programming style,
  771. either interactively or through some other means, your file does *not*
  772. automatically get re-indented.  When you change style parameters, you
  773. will typically need to reformat the line, expression, or buffer to see
  774. the effects of your changes.
  775.  
  776.    Second, changing some variables have no effect on existing code, even
  777. when you do re-indent.  For example, the `c-hanging-*' variables and
  778. `c-cleanup-list' only affect new code as it is typed in on-the-fly, so
  779. changing `c-hanging-braces-alist' and re-indenting the buffer will not
  780. adjust placement of braces already in the file.
  781.  
  782.    Third, re-indenting large portions of code is currently rather
  783. inefficient.  Improvements have been made since previous releases of CC
  784. Mode, and much more radical improvements are planned, but for now you
  785. need to be aware of this (1).  Some provision has been made to at least
  786. inform you as to the progress of the re-indentation.  The variable
  787. `c-progress-interval' controls how often a progress message is
  788. displayed.  Set this variable to `nil' to inhibit progress messages,
  789. including messages normally printed when indentation is started and
  790. completed.
  791.  
  792.    Also, except as noted below, re-indentation is always driven by the
  793. same mechanisms that control on-the-fly indentation of code.  *Note New
  794. Indentation Engine:: for details.
  795.  
  796.    To indent a single line of code, use `TAB' (`c-indent-command').
  797. The behavior of this command is controlled by the variable
  798. `c-tab-always-indent'.  When this variable is `t', `TAB' always just
  799. indents the current line.  When `nil', the line is indented only if
  800. point is at the left margin, or on or before the first non-whitespace
  801. character on the line, otherwise *something else happens*(2).  If the
  802. value of `c-tab-always-indent' is something other than `t' or `nil'
  803. (e.g. `'other'), then a real tab character(3)  is inserted only when
  804. point is inside a literal (see *Note Auto-newline insertion::),
  805. otherwise the line is indented.
  806.  
  807.    To indent an entire balanced brace or parenthesis expression, use
  808. `M-C-q' (`c-indent-exp').  Note that point should be on the opening
  809. brace or parenthesis of the expression you want to indent.
  810.  
  811.    Another very convenient keystroke is `C-c C-q' (`c-indent-defun')
  812. when re-indents the entire top-level function or class definition that
  813. encompasses point.  It leaves point at the same position within the
  814. buffer.
  815.  
  816.    To indent any arbitrary region of code, use `M-C-\'
  817. (`indent-region').   This is a standard Emacs command, specially
  818. tailored for C code in a CC Mode buffer.  Note that of course, point
  819. and mark must delineate the region you want to indent.
  820.  
  821.    While not strictly an indentation function, `M-C-h'
  822. (`c-mark-function') is useful for marking the current top-level
  823. function or class definition as the current region.
  824.  
  825.    ---------- Footnotes ----------
  826.  
  827.    (1) In particular, I have had people complain about the speed with
  828. which `lex(1)' output is re-indented.  Lex, yacc, and other code
  829. generators usually output some pretty perversely formatted code.
  830. *Don't* try to indent this stuff!
  831.  
  832.    (2) Actually what happens is that the function stored in
  833. `c-insert-tab-function' is called.  Normally this just inserts a real
  834. tab character, or the equivalent number of spaces, depending on the
  835. setting of the variable `indent-tabs-mode'.  If you preferred, you
  836. could set `c-insert-tab-function' to `tab-to-tab-stop' for example.
  837.  
  838.    (3) The caveat about `indent-tabs-mode' in the previous footnote
  839. also applies here.
  840.  
  841. 
  842. File: cc-mode.info,  Node: Other Commands,  Prev: Indentation Commands,  Up: Commands
  843.  
  844. Other Commands
  845. ==============
  846.  
  847.    CC Mode contains other useful command for moving around in C code.
  848.  
  849. `C-c C-u (c-up-conditional)'
  850.      Move point back to the containing preprocessor conditional,
  851.      leaving the mark behind.  A prefix argument acts as a repeat
  852.      count.  With a negative argument, move point forward to the end of
  853.      the containing preprocessor conditional.  When going backwards,
  854.      `#elif' is treated like `#else' followed by `#if'.  When going
  855.      forwards, `#elif' is ignored.
  856.  
  857. `C-c C-p (c-backward-conditional)'
  858.      Move point back over a preprocessor conditional, leaving the mark
  859.      behind.  A prefix argument acts as a repeat count.  With a negative
  860.      argument, move forward.
  861.  
  862. `C-c C-n (c-forward-conditional)'
  863.      Move point forward across a preprocessor conditional, leaving the
  864.      mark behind.  A prefix argument acts as a repeat count.  With a
  865.      negative argument, move backward.
  866.  
  867. `M-a (c-beginning-of-statement)'
  868.      Move point to the beginning of the innermost C statement.  If
  869.      point is already at the beginning of a statement, it moves to the
  870.      beginning of the preceding statement.  With prefix argument N,
  871.      move back N - 1 statements.
  872.  
  873.      If point is within a string or comment, or at the end of a
  874.      comment, this command moves by sentences instead of statements.
  875.  
  876.      When called from a program, this function takes three optional
  877.      arguments: the numeric prefix argument, a buffer position limit
  878.      (don't move back before that place), and a flag to indicate
  879.      whether movement should be by statements (if `t') or sentence (if
  880.      non-`nil').
  881.  
  882. `M-e (c-end-of-statement)'
  883.      Move point to the end of the innermost C statement.  If point is
  884.      at the end of a statement, move to the end of the next statement.
  885.      With prefix argument N, move forward N - 1 statements.
  886.  
  887.      If point is within a string or comment, or at the end of a
  888.      comment, this command moves by sentences instead of statements.
  889.  
  890.      When called from a program, this function takes three optional
  891.      arguments: the numeric prefix argument, a buffer position limit
  892.      (don't move back before that place), and a flag to indicate
  893.      whether movement should be by statements (if `t') or sentence (if
  894.      non-`nil').
  895.  
  896. `M-x c-forward-into-nomenclature'
  897.      A popular programming style, especially for object-oriented
  898.      languages such as C++ is to write symbols in a mixed case format,
  899.      where the first letter of each word is capitalized, and not
  900.      separated by underscores.  E.g.
  901.      `SymbolsWithMixedCaseAndNoUnderlines'.
  902.  
  903.      This command moves point forward to next capitalized word.  With
  904.      prefix argument N, move N times.
  905.  
  906. `M-x c-backward-into-nomenclature'
  907.      Move point backward to beginning of the next capitalized word.
  908.      With prefix argument N, move N times.  If N is negative, move
  909.      forward.
  910.  
  911. `C-c : (c-scope-operator)'
  912.      In C++, it is also sometimes desirable to insert the double-colon
  913.      scope operator without performing the electric behavior of colon
  914.      insertion.  `C-c :' does just this.
  915.  
  916. `M-q (fill-paragraph)'
  917.      The command is used to fill a block style (C) or line style (C++)
  918.      comment, in much the same way that text in the various text modes
  919.      can be filled(1).  You should never attempt to fill non-comment
  920.      code sections; you'll end up with garbage!  Two variables control
  921.      how C style block comments are filled, specifically how the
  922.      comment start and end delimiters are handled.
  923.  
  924.      The variable `c-hanging-comment-starter-p' controls whether comment
  925.      start delimiters which appear on a line by themselves, end up on a
  926.      line by themselves after the fill.  When the value is `nil', the
  927.      comment starter will remain on its own line(2).  Otherwise, text
  928.      on the next line will be put on the same line as the comment
  929.      starter.  This is called "hanging" because the following text hangs
  930.      on the line with the comment starter(3)
  931.  
  932.      The variable `c-hanging-comment-ender-p' controls the analogous
  933.      behavior for the block comment end delimiter.  When the value is
  934.      `nil', the comment ender will remain on its own line after the
  935.      file(4).  Otherwise, the comment end delimiter will be placed at
  936.      the end of the previous line.
  937.  
  938.    ---------- Footnotes ----------
  939.  
  940.    (1) You should not use specialized filling packages such as
  941. `filladapt' with CC Mode.  They don't work as well for filling as
  942. `c-fill-paragraph'
  943.  
  944.    (2) It will not be placed on a separate line if it is not already on
  945. a separate line.
  946.  
  947.    (3) This variable is `t' by default, except in `java-mode'.  Hanging
  948. comment starters mess up Javadoc style comments.
  949.  
  950.    (4) The same caveat as above holds true.
  951.  
  952. 
  953. File: cc-mode.info,  Node: Customizing Indentation,  Next: Syntactic Symbols,  Prev: Commands,  Up: Top
  954.  
  955. Customizing Indentation
  956. ***********************
  957.  
  958.    The variable `c-offsets-alist' contains the mappings between
  959. syntactic symbols and the offsets to apply for those symbols.  You
  960. should never modify this variable directly though.  Use the function
  961. `c-set-offset' instead (see below for details).
  962.  
  963.    The `c-offsets-alist' variable is where you customize all your
  964. indentations.  You simply need to decide what additional offset you want
  965. to add for every syntactic symbol.  You can use the command `C-c C-o'
  966. (`c-set-offset') as the way to set offsets, both interactively and from
  967. your mode hook.  Also, you can set up *styles* of indentatio.  Most
  968. likely, you'll find one of the pre-defined styles will suit your needs,
  969. but if not, this section will describe how to set up basic editing
  970. configurations.  *Note Styles:: for an explanation of how to set up
  971. named styles.
  972.  
  973.    As mentioned previously, the variable `c-offsets-alist' is an
  974. association list of syntactic symbols and the offsets to be applied for
  975. those symbols.  In fact, these offset values can be any of an integer, a
  976. function or lambda expression, a variable name, or one of the following
  977. symbols: `+', `-', `++', `--', `*', or `/'.  These symbols describe
  978. offset in multiples of the value of the variable `c-basic-offset'.  By
  979. defining a style's indentation in terms of this fundamental variable,
  980. you can change the amount of whitespace given to an indentation level
  981. while leaving the same relationship between levels.  Here are the
  982. values that the special symbols correspond to:
  983.  
  984. `+'
  985.      `c-basic-offset' times 1
  986.  
  987. `-'
  988.      `c-basic-offset' times -1
  989.  
  990. `++'
  991.      `c-basic-offset' times 2
  992.  
  993. `--'
  994.      `c-basic-offset' times -2
  995.  
  996. `*'
  997.      `c-basic-offset' times 0.5
  998.  
  999. `/'
  1000.      `c-basic-offset' times -0.5
  1001.  
  1002. So, for example, because most of the default offsets are defined in
  1003. terms of `+', `-', and `0', if you like the general indentation style,
  1004. but you use 4 spaces instead of 2 spaces per level, you can probably
  1005. achieve your style just by changing `c-basic-offset' like so (in your
  1006. `.emacs' file):
  1007.  
  1008.      (setq c-basic-offset 4)
  1009.  
  1010. This would change
  1011.  
  1012.      int add( int val, int incr, int doit )
  1013.      {
  1014.        if( doit )
  1015.          {
  1016.            return( val + incr );
  1017.          }
  1018.        return( val );
  1019.      }
  1020.  
  1021. to
  1022.  
  1023.      int add( int val, int incr, int doit )
  1024.      {
  1025.          if( doit )
  1026.              {
  1027.                  return( val + incr );
  1028.              }
  1029.          return( val );
  1030.      }
  1031.  
  1032.    To change indentation styles more radically, you will want to change
  1033. the value associated with the syntactic symbols in the
  1034. `c-offsets-alist' variable.  First, I'll show you how to do that
  1035. interactively, then I'll describe how to make changes to your `.emacs'
  1036. file so that your changes are more permanent.
  1037.  
  1038. * Menu:
  1039.  
  1040. * Interactive Customization::
  1041. * Permanent Customization::
  1042. * Styles::
  1043. * Advanced Customizations::
  1044.  
  1045. 
  1046. File: cc-mode.info,  Node: Interactive Customization,  Next: Permanent Customization,  Up: Customizing Indentation
  1047.  
  1048. Interactive Customization
  1049. =========================
  1050.  
  1051.    As an example of how to customize indentation, let's change the
  1052. style of this example(1):
  1053.  
  1054.      1: int add( int val, int incr, int doit )
  1055.      2: {
  1056.      3:   if( doit )
  1057.      4:     {
  1058.      5:       return( val + incr );
  1059.      6:     }
  1060.      7:   return( val );
  1061.      8: }
  1062.  
  1063. to:
  1064.  
  1065.      1: int add( int val, int incr, int doit )
  1066.      2: {
  1067.      3:   if( doit )
  1068.      4:   {
  1069.      5:     return( val + incr );
  1070.      6:   }
  1071.      7:   return( val );
  1072.      8: }
  1073.  
  1074.    In other words, we want to change the indentation of braces that
  1075. open a block following a condition so that the braces line up under the
  1076. conditional, instead of being indented.  Notice that the construct we
  1077. want to change starts on line 4.  To change the indentation of a line,
  1078. we need to see which syntactic components affect the offset calculations
  1079. for that line.  Hitting `C-c C-s' on line 4 yields:
  1080.  
  1081.      ((substatement-open . 44))
  1082.  
  1083. so we know that to change the offset of the open brace, we need to
  1084. change the indentation for the `substatement-open' syntactic symbol.
  1085. To do this interactively, just hit `C-c C-o' (`c-set-offset').  This
  1086. prompts you for the syntactic symbol to change, providing a reasonable
  1087. default.  In this case, the default is `substatement-open', which is
  1088. just the syntactic symbol we want to change!
  1089.  
  1090.    After you hit return, CC Mode will then prompt you for the new
  1091. offset value, with the old value as the default.  The default in this
  1092. case is `+', but we want no extra indentation so enter `0' and `RET'.
  1093. This will associate the offset 0 with the syntactic symbol
  1094. `substatement-open' in the `c-offsets-alist' variable.
  1095.  
  1096.    To check your changes quickly, just hit `C-c C-q' (`c-indent-defun')
  1097. to reindent the entire function.  The example should now look like:
  1098.  
  1099.      1: int add( int val, int incr, int doit )
  1100.      2: {
  1101.      3:   if( doit )
  1102.      4:   {
  1103.      5:     return( val + incr );
  1104.      6:   }
  1105.      7:   return( val );
  1106.      8: }
  1107.  
  1108.    Notice how just changing the open brace offset on line 4 is all we
  1109. needed to do.  Since the other affected lines are indented relative to
  1110. line 4, they are automatically indented the way you'd expect.  For more
  1111. complicated examples, this may not always work.  The general approach to
  1112. take is to always start adjusting offsets for lines higher up in the
  1113. file, then re-indent and see if any following lines need further
  1114. adjustments.
  1115.  
  1116.    ---------- Footnotes ----------
  1117.  
  1118.    (1) In this an subsequent examples, the original code is formatted
  1119. using the `gnu' style unless otherwise indicated. *Note Styles::.
  1120.  
  1121. 
  1122. File: cc-mode.info,  Node: Permanent Customization,  Next: Styles,  Prev: Interactive Customization,  Up: Customizing Indentation
  1123.  
  1124. Permanent Customization
  1125. =======================
  1126.  
  1127.    To make your changes permanent, you need to add some lisp code to
  1128. your `.emacs' file, but first you need to decide whether your styles
  1129. should be global in every buffer, or local to each specific buffer.
  1130.  
  1131.    If you edit primarily one style of code, you may want to make the CC
  1132. Mode style variables have global values so that every buffer will share
  1133. the style settings.  This will allow you to set the CC Mode variables
  1134. at the top level of your `.emacs' file, and is the way CC Mode works by
  1135. default.
  1136.  
  1137.    If you edit many different styles of code at the same time, you
  1138. might want to make the CC Mode style variables have buffer local
  1139. values.  If you do this, then you will need to set any CC Mode style
  1140. variables in a hook function (e.g. off of `c-mode-common-hook' instead
  1141. of at the top level of your `.emacs' file.  The recommended way to do
  1142. this is to set the variable `c-style-variables-are-local-p' to `t'
  1143. *before* CC Mode is loaded into your Emacs session.
  1144.  
  1145.    CC Mode provides several hooks that you can use to customize the
  1146. mode according to your coding style.  Each language mode has its own
  1147. hook, adhering to standard Emacs major mode conventions.  There is also
  1148. one general hook and one package initialization hook:
  1149.  
  1150.    * `c-mode-hook' -- for C buffers only
  1151.  
  1152.    * `c++-mode-hook' -- for C++ buffers only
  1153.  
  1154.    * `objc-mode-hook' -- for Objective-C buffers only
  1155.  
  1156.    * `java-mode-hook' -- for Java buffers only
  1157.  
  1158.    * `idl-mode-hook' -- for IDL buffers only
  1159.  
  1160.    * `c-mode-common-hook' -- common across all languages
  1161.  
  1162.    * `c-initialization-hook' -- hook run only once per Emacs session,
  1163.      when CC Mode is initialized.
  1164.  
  1165.    The language hooks get run as the last thing when you enter that
  1166. language mode.  The `c-mode-common-hook' is run by all supported modes
  1167. *before* the language specific hook, and thus can contain
  1168. customizations that are common across all languages.  Most of the
  1169. examples in this section will assume you are using the common hook(1).
  1170.  
  1171.    Here's a simplified example of what you can add to your `.emacs'
  1172. file to make the changes described in the previous section (*Note
  1173. Interactive Customization::) more permanent.  See the Emacs manuals for
  1174. more information on customizing Emacs via hooks.  *Note Sample .emacs
  1175. File:: for a more complete sample `.emacs' file.
  1176.  
  1177.      (defun my-c-mode-common-hook ()
  1178.        ;; my customizations for all of c-mode and related modes
  1179.        (c-set-offset 'substatement-open 0)
  1180.        ;; other customizations can go here
  1181.        )
  1182.      (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1183.  
  1184.    For complex customizations, you will probably want to set up a
  1185. *style* that groups all your customizations under a single name.
  1186.  
  1187.    ---------- Footnotes ----------
  1188.  
  1189.    (1) The interaction between `java-mode' and the hook variables is
  1190. slightly different than for the other modes.  `java-mode' sets the
  1191. style (see *Note Styles::) of the buffer to `java' *before* running the
  1192. `c-mode-common-hook' or `java-mode-hook'.  You need to be aware of this
  1193. so that style settings in `c-mode-common-hook' don't clobber your Java
  1194. style.
  1195.  
  1196. 
  1197. File: cc-mode.info,  Node: Styles,  Next: Advanced Customizations,  Prev: Permanent Customization,  Up: Customizing Indentation
  1198.  
  1199. Styles
  1200. ======
  1201.  
  1202.    Most people only need to edit code formatted in just a few
  1203. well-defined and consistent styles.  For example, their organization
  1204. might impose a "blessed" style that all its programmers must conform
  1205. to.  Similarly, people who work on GNU software will have to use the
  1206. GNU coding style on C code.  Some shops are more lenient, allowing a
  1207. variety of coding styles, and as programmers come and go, there could
  1208. be a number of styles in use.  For this reason, CC Mode makes it
  1209. convenient for you to set up logical groupings of customizations called
  1210. "styles", associate a single name for any particular style, and pretty
  1211. easily start editing new or existing code using these styles.  This
  1212. section describes how to set up styles and how to edit your C code
  1213. using styles.
  1214.  
  1215. * Menu:
  1216.  
  1217. * Built-in Styles::
  1218. * Adding Styles::
  1219. * File Styles::
  1220.  
  1221.